package 大数乘法;

public class Solution {

    public String solve(String ss, String tt) {
        String s = new StringBuffer(ss).reverse().toString();
        String t = new StringBuffer(tt).reverse().toString();
        StringBuffer ret = new StringBuffer();
        int n = s.length(), m = t.length();
        int[] tmp = new int[n + m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                tmp[i + j] += (s.charAt(i) - '0') * (t.charAt(j) - '0');
            }
        }
        int c = 0;
        for (int x : tmp) {
            c += x;
            ret.append((char) (c % 10 + '0'));
            c /= 10;
        }
        while (c != 0) {
            ret.append((char) (c % 10 + '0'));
            c /= 10;
        }
        while (ret.length() > 1 && ret.charAt(ret.length() - 1) == '0') {
            ret.deleteCharAt(ret.length() - 1);
        }
        return ret.reverse().toString();
    }
}
